home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EGAVGA.SWG / 0134_640x480x16 Mode Programming.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  5KB  |  270 lines

  1. {
  2. > 640/480/16 mode... Yes I know how to put a pixel with the
  3. > What I want is Line, Bitmap procedure...
  4.  
  5. The first is mine, the second a bit.
  6. }
  7.  
  8. procedure FillBox(X1,Y1,X2,Y2:word; Color:byte); assembler;
  9. { Fill (X1,Y1)-(X2,Y1) with Color, VGA only, 640 lines, 16 color mode, PD }
  10. asm
  11.  cld
  12.  mov dx,3ceh
  13.  mov ah,Color
  14.  mov al,0
  15.  out dx,ax
  16.  mov ax,0305h
  17.  out dx,ax
  18.  mov ax,0a000h
  19.  mov es,ax
  20.  mov ax,Y1
  21.  mov si,Y2
  22.  sub si,ax
  23.  jz @NoLines
  24.  {$ifopt G+}shl ax,6{$else}mov cl,6;shl ax,cl{$endif}
  25.  mov di,ax
  26.  {$ifopt G+}shr ax,2{$else}shr ax,1; shr ax,1{$endif}
  27.  add di,ax
  28.  mov ax,X1
  29.  mov cl,al
  30.  {$ifdef G+}shr ax,3{$else}shr ax,1; shr ax,1; shr ax,1{$endif}
  31.  mov bx,X2
  32.  mov ch,bl
  33.  {$ifdef G+}shr bx,3{$else}shr bx,1; shr bx,1; shr bx,1{$endif}
  34.  sub bx,ax
  35.  push bp
  36.  mov bp,bx
  37.  add di,ax
  38.  and cx,707h
  39.  mov bx,0ffffh
  40.  shr bl,cl
  41.  mov cl,ch
  42.  xor cl,7
  43.  inc cx
  44.  shl bh,cl
  45.  or bp,bp
  46.  jnz @NoDub
  47.  and bl,bh
  48.  jz @NoLines2
  49. @NoDub:
  50.  mov al,8
  51. @PutLines:
  52.  cli
  53.  mov al,es:[di]
  54.  mov es:[di],bl
  55.  sti
  56.  inc di
  57.  mov cx,bp
  58.  dec cx
  59.  js @NoPBL
  60.  jz @NoPB
  61.  mov al,0ffh
  62.  rep stosb
  63. @NoPB:
  64.  cli
  65.  mov al,es:[di]
  66.  mov es:[di],bh
  67.  sti
  68.  inc di
  69. @NoPBL:
  70.  sub di,bp
  71.  add di,80-1
  72.  dec si
  73.  jnz @PutLines
  74. @NoLines2:
  75.  pop bp
  76. @NoLines:
  77.  mov ax,0005h
  78.  out dx,ax
  79. end;
  80.  
  81. procedure PixelAddrHGC; assembler;
  82. asm
  83.  mov cl,bl
  84.  {$ifopt G+}shr bx,3{$else}shr bx,1;shr bx,1;shr bx,1{$endif}
  85.  {$ifopt G+}shl ax,6{$else}mov ch,cl; mov cl,6; shl ax,cl; mov cl,ch;{$endif}
  86.  add bx,ax
  87.  {$ifopt G+}shr ax,2{$else}shr ax,1; shr ax,1;{$endif}
  88.  add bx,ax
  89.  mov ax,0a000h
  90.  mov es,ax
  91.  and cl,7
  92.  xor cl,7
  93.  mov ah,1
  94. end;
  95.  
  96. procedure Line(X1,Y1,X2,Y2:word; Color:byte); assembler;
  97. { Draw a line from (X1,Y1)-(X2,Y2) in Color, VGA only, 640 lines, 16 colors }
  98. { Originally from a HGC line routine in a book, converted to VGA by me }
  99. const
  100.  ByteOffsetShift=3;
  101. var
  102.  Incr1,Incr2:word;
  103.  Routine:word;
  104. asm
  105.         cld
  106.         mov si,80
  107.         mov dx,3ceh
  108.         mov ah,Color
  109.         xor al,al
  110.         out dx,ax
  111.         mov ax,0305h
  112.         out dx,ax
  113.         mov cx,X2
  114.         sub cx,X1
  115.         jz @VertLineHGC    { Jump if X1=X2, VertLine }
  116.         jns @Li01          { Jump if X2>X1, no swap }
  117.         neg cx
  118.         mov bx,X2
  119.         xchg bx,X1
  120.         mov X2,bx
  121.         mov bx,Y2
  122.         xchg bx,Y1
  123.         mov Y2,bx
  124. @Li01:  mov bx,Y2
  125.         sub bx,Y1
  126.         jnz @Li02          { Jump if Y1<>Y2, no HorizLine }
  127.         jmp @HorizLineHGC
  128. @Li02:  jns @Li03          { Jump if Y2 > Y1, no swap }
  129.         neg bx
  130.         neg si
  131. @Li03:  mov routine,offset @LoSlopeLineHGC
  132.         cmp bx,cx
  133.         jle @Li04
  134.         mov routine,offset @HiSlopeLineHGC
  135.         xchg bx,cx
  136. @Li04:  shl bx,1
  137.         mov incr1,bx
  138.         sub bx,cx
  139.         mov di,bx
  140.         sub bx,cx
  141.         mov incr2,bx
  142.         push cx
  143.         mov ax,Y1
  144.         mov bx,X1
  145.         call PixelAddrHGC
  146.         mov al,1
  147.         shl ax,cl
  148.         mov dx,ax
  149.         not dh
  150.         pop cx
  151.         inc cx
  152.         jmp routine          { Var containing LoSlope/HiSlope }
  153.  
  154. @VertLineHGC: mov ax,Y1
  155.         mov bx,Y2
  156.         mov cx,bx
  157.         sub cx,ax
  158.         jge @Li31
  159.         neg cx
  160.         mov ax,bx
  161. @Li31:  inc cx
  162.         mov bx,X1
  163.         push cx
  164.         call PixelAddrHGC
  165.         mov al,1
  166.         shl ax,cl
  167.         not ah
  168.         pop cx
  169. @Li32:  mov ah,es:[bx]
  170.         mov es:[bx],al
  171.         add bx,si
  172.         loop @Li32
  173.         jmp @Liexit
  174.  
  175. @HorizLineHGC:
  176.         mov ax,Y1
  177.         mov bx,X1
  178.         call PixelAddrHGC
  179.         mov di,bx
  180.         mov dh,ah
  181.         not dh
  182.         mov dl,0ffh
  183.         shl dh,cl
  184.         not dh
  185.         mov cx,X2
  186.         and cl,7
  187.         xor cl,7
  188.         shl dl,cl
  189.         mov ax,X2
  190.         mov bx,X1
  191.         mov cl,ByteOffsetShift
  192.         shr ax,cl
  193.         shr bx,cl
  194.         mov cx,ax
  195.         sub cx,bx
  196.         mov ax,0ffffh
  197.         or dh,dh
  198.         js @Li43
  199.         or cx,cx
  200.         jnz @Li42
  201.         and dl,dh
  202.         jmp @Li44
  203. @Li42:  mov ah,al
  204.         and ah,dh
  205.         mov bl,es:[di]
  206.         mov es:[di],ah
  207.         inc di
  208.         dec cx
  209. @Li43:  or cx,cx
  210.         jz @Li44
  211. @InLoop: mov bl,es:[di]
  212.         stosb
  213.         loop @InLoop
  214.       {  if mode = NO_OP replace 'or cx,cx'-'loop @InLoop:' with 'rep stosb'}
  215. @Li44:  and al,dl
  216.         mov dl,es:[di]
  217.         mov es:[di],al
  218.         jmp @Liexit
  219.  
  220. @LoSlopeLineHGC:
  221. @Li10:  mov ah,es:[bx]
  222.         xor ah,ah
  223. @Li11:  or ah,dl
  224.         ror dl,1
  225.         ror dh,1
  226.         jnc @Li14
  227.         or di,di
  228.         jns @Li12
  229.         add di,incr1
  230.         loop @Li11
  231.         mov es:[bx],ah
  232.         jmp @Liexit
  233. @Li12:  add di,incr2
  234.         mov es:[bx],ah
  235.         add bx,si
  236.         loop @Li10
  237.         jmp @Liexit
  238. @Li14:  mov es:[bx],ah
  239.         inc bx
  240.         or di,di
  241.         jns @Li15
  242.         add di,incr1
  243.         loop @Li10
  244.         jmp @Liexit
  245. @Li15:  add di,incr2
  246.         add bx,si
  247.         loop @Li10
  248.         jmp @Liexit
  249.  
  250. @HiSlopeLineHGC:
  251. @Li21:  mov al,es:[bx]
  252.         mov es:[bx],dl
  253.         add bx,si
  254.         or di,di
  255.         jns @Li23
  256.         add di,incr1
  257.         loop @Li21
  258.         jmp @Liexit
  259. @Li23:  add di,incr2
  260.         ror dl,1
  261.         ror dh,1
  262.         cmc
  263.         adc bx,0
  264.         loop @Li21
  265. @Liexit:
  266.  mov dx,3ceh
  267.  mov ax,5
  268.  out dx,ax
  269. end;
  270.